#!/usr/bin/perl
# Show a page for manually editing smb.conf

require '../netebbms-lib.pl';


# read argument in %in
&ReadParse();


# load config file
$cfgObj = new Config::Simple(syntax=>'ini');
$cfgObj->read($config{'twitterclient_conf'});  # need check!
#print $cfgObj->param('account.consumerkey');


# show header
&ui_print_header(undef, $text{'rssreader_title'}, '', undef, 1, 1);


print &ui_form_start('save.cgi', 'post', undef, 'name="configform"');

@tabs = (
	['url', $text{'rssreader_urlcfgtitle'}, 'index.cgi?tab=url'],
	['behavior', $text{'twitterclient_behaviorcfgtitle'}, 'index.cgi?tab=behavior'],
	['style', $text{'twitterclient_stylecfgtitle'}, 'index.cgi?tab=style'],
);
print &ui_tabs_start(\@tabs, 'tabs', $in{'tab'} || $tabs[1][0]);


# url config #
print &ui_tabs_start_tab('tabs', 'url');
print &ui_table_start($text{'rssreader_urlcfgtitle'}, undef, 2);

print &ui_table_row($text{'twitterclient_consumerkey_title'},
	&ui_textbox('consumerkey', $in{'consumerkey'} || $cfgObj->param('account.consumerkey') || undef, 40, 0, 21, 'id="consumerKey"'));
print &ui_table_row($text{'twitterclient_consumersecret_title'},
	&ui_textbox('consumersecret', $in{'consumersecret'} || $cfgObj->param('account.consumersecret') || undef,
		40, 0, 41, 'id="consumerSecret"'));

print &ui_table_row('&nbsp;', &ui_button($text{'twitterclient_openauthbutton_title'}, undef, 0, 'onClick="getPinKey()"'));
print &ui_table_row('&nbsp;', '&nbsp;');

print &ui_hidden('requesttoken', '');
print &ui_hidden('requestsecret', '');

print &ui_table_row($text{'twitterclient_pinkey_title'},
	&ui_password('pinkey', undef, 10, 0, 7, 'id="pinKey"') .
	&ui_button($text{'twitterclient_doauthbutton_title'}, undef, 0, 'onClick="getAccessToken()"'));
print &ui_table_row('&nbsp;', '&nbsp;');

print &ui_table_row($text{'twitterclient_accesstokenkey_title'},
	&ui_textbox('accesstokenkey', $in{'accesstokenKey'} || $cfgObj->param('account.accesstokenkey') || undef,
		40, 0, 50, 'id="accessTokenKey"'));
print &ui_table_row($text{'twitterclient_accesstokensecret_title'},
	&ui_textbox('accesstokensecret', $in{'accesstokensecret'} || $cfgObj->param('account.accesstokensecret') || undef,
		40, 0, 50, 'id="accessTokenSecret"'));

print &ui_table_end();
print &ui_tabs_end_tab();

# behavior config #
print &ui_tabs_start_tab('tabs', 'behavior');
print &ui_table_start($text{'twitterclient_behaviorcfgtitle'}, undef, 2);

my @options = (
	['friends', $text{'twitterclient_friends'}],
	['followers', $text{'twitterclient_followers'}],
);
my @default = split(/\0/, $in{'tweetselect'}) || $cfgObj->param('behavior.tweetselect');
print &ui_table_row($text{'twitterclient_tweet'},
	&ui_select('tweetselect', \@default, \@options, 3, 1));
print &ui_table_row($text{'twitterclient_timeout'},
	&ui_textbox('timeout', $in{'timeout'} || $cfgObj->param('behavior.timeout') || $options[0][0], 10, 0));
print &ui_table_row($text{'twitterclient_hashtag'},
	&ui_textbox('hashtags', join(',', split(/\0/, $in{'hashtags'}) || $cfgObj->param('behavior.hashtags')), 30, 0));

print &ui_table_end();
print &ui_tabs_end_tab();


# style config #
print &ui_tabs_start_tab('tabs', 'style');
print &ui_table_start($text{'twitterclient_stylecfgtitle'}, undef, 2);

print &ui_table_row($text{'twitterclient_fontpath'},
	&ui_textbox('fontpath', $in{'fontpath'} || $cfgObj->param('style.fontpath'), 30, 0) . &file_chooser_button('fontpath', 0));
print &ui_table_row($text{'twitterclient_point'},
	&ui_textbox('point', $in{'point'} || $cfgObj->param('style.point') || $options[0][0], 10, 0));
print &ui_table_row($text{'twitterclient_scroll'},
	&ui_textbox('scroll', $in{'scroll'} || $cfgObj->param('style.scroll'), 10, 0));
print &ui_table_row($text{'twitterclient_positionY'},
	&ui_textbox('positionY', $in{'positionY'} || $cfgObj->param('style.positionY'), 10, 0));

print &ui_table_end();
print &ui_tabs_end_tab();


print &ui_tabs_end();
print &ui_form_end([['save', $text{'save'}]]);


# show footer
&ui_print_footer('', $text{'index_title'});

